package com.heima.article.listener;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WmNewsMessageConstants;
import com.heima.model.common.msg.UpDownMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
@Slf4j
@Component
public class ArticleIsDownListener {

    @Resource
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void update(String msg){
        if (ObjectUtil.isNotEmpty(msg)){
            log.info("article端文章配置修改，msg = {}", msg);
            UpDownMsg upDownMsg = JSONUtil.toBean(msg, UpDownMsg.class);
            apArticleConfigService.updateStatus(upDownMsg);
        }
    }


}
